package com.app.teaware.bean;


import android.text.TextUtils;

import java.util.ArrayList;

public class ProvinceListBean extends BaseListBeanXF {

    private ArrayList<ProviceListData> list = new ArrayList<ProviceListData>();

    public ArrayList<ProviceListData> getList() {
        return list;
    }

    public void setList(ArrayList<ProviceListData> list) {
        this.list = list;
    }

    public ArrayList<String> getListStr(){
        ArrayList<String> listStr = new ArrayList<>();
        for (ProviceListData data:list){
            listStr.add(data.getTitle());
        }
        return listStr;
    }

    public int getSeletedProvincePosition(String province){
        if(TextUtils.isEmpty(province))return -1;
        int i = 0;
        for (ProviceListData data:list){
          if( province.equals(data.getTitle())){
              return i;
          }
            i++;
        }

        return -1;
    }

    public int getSeletedCityPosition(String province,String cityName){
        if(TextUtils.isEmpty(province))return -1;
        if(TextUtils.isEmpty(cityName))return -1;
        int provinceIndex = getSeletedProvincePosition(province);
        if(provinceIndex < 0)return  -1;
        ProviceListData data = list.get(provinceIndex);
        if(data.getChildren() == null || data.getChildren().size() == 0)return  -1;
        for(int i = 0 , l = data.getChildren().size() ; i < l ; i ++){
            if(data.getChildren().get(i).getTitle().equals(cityName)){
                return i;
            }
        }
        return -1;
    }
}
